<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>委外催收</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<script type="text/javascript">
    var grid = null, pageInTab = null;
    $(function () {
        initTab();
        initGrid();//grid

        $("#searchBar").ligerForm();
        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

    });

    function clearBtn() {
        $("#searchBar").ligerForm();
        var form = new liger.get("searchBar");
        var authOrgCd = liger.get("authOrgCd");
        authOrgCd.selectValue("");
        form.setData({
            paySchNo: " ",
            cstNm: " ",
            minOverdueDay: " ",
            maxOverdueDay: " ",
            startDate : " ",
            endDate : " ",
            authOrgCd:""
        });
    }

    //初始化列表
    function initGrid() {
        var params = {};
        $("#grid").ligerGrid({
            url: '<%=path%>/clt/auth/rskCltAuth/initRskCltAuthCollectionList.do',
            method: 'get',
            parms: params,
            columns: [
                {display: '事业部', name: 'buOrgNm', width: 140, align: 'center', enabledSort: true},
                {display: '省公司', name: 'cstMgrOrgCdNm', width: 160, align: 'center', enabledSort: true},
                {
                    display: '承租人', name: 'cstNm', width: 100, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        if(StringUtils.isEmpty(value)){
                            value = "";
                        }
                        var h = '<a href="javascript:showDetail(';
                        h += "'" + rowdata.cstId + "'";
                        h += ",'" + rowdata.cstTypCd + "'";
                        h += ')">' + value + '</a>'
                        return h;
                    }
                },
                {display: '支付表号', name: 'paySchNo', width: 200, align: 'center', enabledSort: true},
                {display: '逾期天数', name: 'overdueDay', width: 100, align: 'center', enabledSort: true},
                {display: '委案机构', name: 'authOrgCdNm', width: 100, align: 'center', enabledSort: true},
                {display: '委案剩余天数', name: 'residueAuthDay', width: 100, align: 'center', enabledSort: true},
                {
                    display: '委案金额', name: 'authAmt', width: 120, align: 'center', enabledSort: true,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.authAmt / 100);
                    }
                },
                {
                    display: '委案时间',
                    name: 'startDate',
                    width: 100,
                    align: 'center',
                    enabledSort: true,
                    render: renderDate
                },
                {
                    display: '已回款金额', name: 'recoveryAmt', width: 100, align: 'center', enabledSort: true,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.recoveryAmt / 100);
                    }
                },
                {
                    display: '操作', name: 'flowId', width: 300, align: 'center', enabledSort: true,
                    render: function (rowdata, rowindex, value, column) {
                        var paySchId = rowdata.paySchId == null ? " " : rowdata.paySchId;
                        var h = '';
                        if (paySchId == " ") {
                            h += "";
                        } else {
                            h += '<a href="javascript:showFileDetail(';
                            h += "'" + rowdata.paySchId + "'";
                            h += ')">资料</a>';
                            h += ' | ';
                            h += '<a href="javascript:showRebatePage(';
                            h += "'" + rowdata.id + "'";
                            h += ')">回款申请</a>';
                            h += ' | ';
                            h += '<a href="javascript:showAddCltRcdPage(';
                            h += "'" + rowdata.id + "'";
                            h += ')">添加催收记录</a>';
                            h += ' | ';
                            h += '<a href="javascript:backoutRskCltAuth(';
                            h += "'" + rowdata.id + "'";
                            h += ')">退案</a>';
                        }
                        return h;
                    }
                }
            ],
            pageSize: 10,
            isSingleCheck: true,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            detail: {
                height: 'auto',
                onShowDetail: showRentList
            }
        });
        grid = liger.get("grid");
        grid.setHeight(500);
    }

    function showRentList(row, detailPanel, callback) {
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({'padding': 10, 'box-sizing': 'border-box'}).append(gridBox);
        $(gridBox).ligerGrid({
            url: '<%=path%>/clt/auth/rskCltAuth/loadRentList.do?paySchId=' + row.paySchId,
            method: 'get',
            columns: [
                {display: '费用类型', name: 'feeTypCdNm', width: 100, align: 'center'},
                {display: '期次', name: 'payPd', width: 150, align: 'center'},
                {display: '应收日期', name: 'payDt', width: 150, align: 'center', render: renderDate},
                {
                    display: '应收金额', name: 'feeAmt', width: 110, align: 'center',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(value / 100);
                    }
                },
                {
                    display: '已付金额', name: 'paidUpAmt', width: 110, align: 'center',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(value / 100);
                    }
                },
                {
                    display: '未付金额', name: 'arAmt', width: 110, align: 'center',
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(value / 100);
                    }
                }
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    //格式化为人民币格式
    function renderAmt(rowdata, rowindex, value) {
        var h = "￥" + FormatMoney(value);
        return h;
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value && value != '') {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //查看数据
    function showDetail(_id, _cstTypCd) {
        //1 自然人  2 法人
        //parent.mainApp.f_addTab
        if(_cstTypCd == 1){
            Add_navTab('tab_customer_np_detail'+_id,'客户详情','<%=path%>/clt/auth/rskCltAuth/toCustCstBacInfoNpDetailPage.do?id='+_id);
        }else if(_cstTypCd == 2){
            Add_navTab('tab_customer_corp_detail'+_id,'客户详情','<%=path%>/clt/auth/rskCltAuth/toCustCstBacInfoCorpDetailPage.do?id='+_id);
        }
    }

    // 退案
    function backoutRskCltAuth(id) {
        $.ligerDialog.confirm("退案之后将无法查看已退案记录,是否确认退案?", function (flag) {
            if (flag == false) return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {id: id,authStsCd:"3"},
                url: '<%=path%>/clt/auth/rskCltAuth/modify.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({
                        content: LogUtils.LOG_CMM_DATA_LOADING,
                        SQ_type: "waitting"
                    });
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: "退案成功", SQ_type: "success"});
                        grid.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    /* 回款申请 */
    function showRebatePage(id) {
        var onOk = function (item, Dialog) {
            if (Dialog.onOk) Dialog.onOk();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 850,
            height: 300,
            title: '回款申请',
            url: '<%=path%>/clt/auth/rebate/showAddRebatePage.do?cltAuthId=' + id,
            buttons: [{
                text: "提交申请", type: 'ok', onclick: onOk
            }, {
                text: "关闭", type: 'cancel', onclick: onCancel, cls: 'l-dialog-btn-no'
            }]
        });
    }

    /* 添加催收记录 */
    function showAddCltRcdPage(id) {
        var onOk = function (item, Dialog) {
            if (Dialog.onOk) Dialog.onOk();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 850,
            height: 400,
            title: '添加催收记录',
            url: '<%=path%>/clt/auth/record/showAddCltRcdPage.do?cltAuthId=' + id,
            buttons: [{
                text: "保存", type: 'ok', onclick: onOk
            }, {
                text: "关闭", type: 'cancel', onclick: onCancel, cls: 'l-dialog-btn-no'
            }]
        });
    }


    /**
     * 资料
     */
    function showFileDetail(paySchId) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.open({
            width: 850,
            height: 300,
            title: '资料维护',
            url: '<%=path%>/clt/auth/file/toCltFileListPage.do?paySchId=' + paySchId,
            buttons: [{
                text: "关闭", type: 'cancel', onclick: onCancel, cls: 'l-dialog-btn-no'
            }]
        });
    }

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onBeforeSelectTabItem: function(tabid) {
                if (tabid == "tabB") {
                    var selectedRows = grid.getSelectedRows();
                    if (selectedRows.length != 1) {
                        $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                        return false;
                    }
                }
            },
            onAfterSelectTabItem: function(tabid) {
                switch (tabid) {
                    case "tabB":
                        var selectedRows = grid.getSelectedRows();
                        pageInTab.setTabItemSrc(tabid, "<%=path%>/clt/auth/flow/showFlowTracePage.do?cltAuthId=" + selectedRows[0].id);
                        break;
                    case "tabC":
                        if (pageInTab.getTabItemSrc(tabid) == "") {
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/clt/auth/record/toListPage.do");
                            break;
                        }
                }
                SetIframe_height();
            }
        });
    }
</script>

<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="委外催收" lselected="true">
            <div class="searchArea">
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <div class="fieldBox col_33" id="searchCstNm">
                            <div class="label">支付表号</div>
                            <div class="field">
                                <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox col_33" id="searchCstNmId">
                            <div class="label">承租人</div>
                            <div class="field">
                                <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">委案开始时间</div>
                            <div class="field">
                                <input ligerui="width: 110" name="startDate" id="startDate" type="text"
                                       class="ui-datepicker"
                                       value="">
                                -
                                <input ligerui="width: 110" name="endDate" id="endDate" type="text" class="ui-datepicker"
                                       value="">
                            </div>
                        </div>
                        <div class="fieldBox">
                            <div class="label">逾期天数</div>
                            <div class="field">
                                <input ligerui="width: 82" name="minOverdueDay" id="minOverdueDay" type="text"
                                       class="ui-textbox"
                                       value="" validate="{number:true}">
                                -
                                <input ligerui="width: 82" name="maxOverdueDay" id="maxOverdueDay" type="text"
                                       class="ui-textbox"
                                       value="" validate="{number:true}">
                            </div>
                        </div>
                        <c:if test="${showAuthOrg == '0'}">
                        <div class="fieldBox col_33" >
                            <div class="label">委案机构</div>
                            <div class="field">
                                <select name="authOrgCd" id="authOrgCd" data-value=" ">
                                    <option value=" " seleted>请选择</option>
                                    <c:forEach items="${authOrgList}" var="authOrg">
                                        <option value="${authOrg.id}">${authOrg.refRlNm}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        </c:if>
                        <div class="clearFix"></div>
                        <div class="btnsBox">
                            <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                            <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                        </div>
                    </div>
                </form>
            </div>
            <div id="grid" class="sq-grid"></div>
        </div>
        <div tabid="tabB" title="流程跟踪" id="tabBId">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>
        <div tabid="tabC" title="催收记录" id="tabCId">
            <iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
        </div>
    </div>
</div>
</body>
</html>